import { ref, reactive } from 'vue'
import { TASK_QUESTION_STATUS, TASK_QUESTION_TYPE } from '@/utils/dictionary'
import { getTaskInspectionType } from '@/api/task/index'
import { arrToObj } from '@/utils/handleData'

// 问题类型列表
const typeList = ref([])

export const search = reactive({
  search: [
    {
      label: '问题类型',
      type: 'select',
      key: 'questionCode',
      props: {
        placeholder: '请选择问题类型',
        options: typeList
      }
    },
    {
      label: '问题状态',
      type: 'select',
      key: 'status',
      props: {
        placeholder: '请选择问题状态',
        options: TASK_QUESTION_STATUS
      }
    }
  ]
})

// 获取问题类型列表
export const getTypeList = async function() {
  const { data } = await getTaskInspectionType()
  typeList.value = data.map(it => ({
    ...it,
    label: it.content,
    value: it.code
  }))
}

